package com.baobao.service;

import com.baobao.domain.Course;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/bb-security-context.xml",
		"file:./resources/bb-service-context.xml",
		"file:./resources/bb-dao-context.xml",
		"file:./resources/bb-web-context.xml" })
@Transactional
public class CourseServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected CourseService service;

	/**
	 * Instantiates a new CourseServiceTest.
	 *
	 */
	public CourseServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Course entity
	 * 
	 */
	@Test
	public void deleteCourse() {
		// TODO: JUnit - Populate test inputs for operation: deleteCourse 
		Course course = new com.baobao.domain.Course();
		service.deleteCourse(course);
	}

	/**
	 * Operation Unit Test
	 * Load an existing Course entity
	 * 
	 */
	@Test
	public void loadCourses() {
		Set<Course> response = null;
		response = service.loadCourses();
		// TODO: JUnit - Add assertions to test outputs of operation: loadCourses
	}

	/**
	 * Operation Unit Test
	 * Return all Course entity
	 * 
	 */
	@Test
	public void findAllCourses() {
		// TODO: JUnit - Populate test inputs for operation: findAllCourses 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Course> response = null;
		response = service.findAllCourses(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllCourses
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findCourseByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findCourseByPrimaryKey 
		String banjiId = null;
		Integer weekDay = 0;
		Integer seqNo = 0;
		Course response = null;
		response = service.findCourseByPrimaryKey(banjiId, weekDay, seqNo);
		// TODO: JUnit - Add assertions to test outputs of operation: findCourseByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Save an existing Course entity
	 * 
	 */
	@Test
	public void saveCourse() {
		// TODO: JUnit - Populate test inputs for operation: saveCourse 
		Course course_1 = new com.baobao.domain.Course();
		service.saveCourse(course_1);
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Course entity
	 * 
	 */
	@Test
	public void countCourses() {
		Integer response = null;
		response = service.countCourses();
		// TODO: JUnit - Add assertions to test outputs of operation: countCourses
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
